﻿using System.Collections.Generic;
using System.Linq;

namespace Sidvall.IdentityManager.Data.Model.EntityManagers
{
    public partial class AspNetUserClaimsManager<TEntity, TList>
    {
        #region Public Members

        #region GetClaim

        public IAspNetUserClaims GetClaim(IEnumerable<IAspNetUserClaims> items, string claimType)
        {
            if (items == null)
                return null;
            return (from o in items
                    where o.ClaimType.Equals(claimType, System.StringComparison.OrdinalIgnoreCase)
                    select o).FirstOrDefault();
        }

        #endregion
        #region GetClaimValue

        public string GetClaimValue(IEnumerable<IAspNetUserClaims> items, string claimType)
        {
            var property = GetClaim(items, claimType);
            if (property == null)
                return null;
            return property.ClaimValue;
        }
        public string GetClaimValue(IEnumerable<IAspNetUserClaims> items, string claimType, string defaultValue)
        {
            var property = GetClaim(items, claimType);
            if (property == null)
                return defaultValue;
            if (property.ClaimValue == null)
                return defaultValue;
            return property.ClaimValue;
        }

        #endregion
        #region HasClaim

        public bool HasClaim(IEnumerable<IAspNetUserClaims> items, string claimType)
        {
            if (items == null)
                return false;
            return (from o in items
                    where o.ClaimType.Equals(claimType, System.StringComparison.OrdinalIgnoreCase)
                    select o).Any();
        }

        #endregion

        #endregion
    }
}